import pytest
import requests

import config
from api.tpshop_api import TpshopApi
from common.mysql_tool import DBUtil
from common.read_data import read_tpshopRegister
from common.tpshop_assert import tpshopcommon


class TestTpshopRegister:
    # 定义类属性
    session = None


    # 定义session，所有用例执行前执行
    def setup_class(self):
        self.session = requests.session()

    # 获取验证码，每条用例执行前执行
    def setup(self):
        TpshopApi.get_code01(self.session)


    @pytest.mark.parametrize("username, verify_code, password, password2, state_code, status, msg",
                             read_tpshopRegister())
    def test(self, username, verify_code, password, password2, state_code, status, msg):
        register_data = {"username": username,
                         "verify_code": verify_code,
                         "password": password,
                         "password2": password2}
        # print("register_data=", register_data)
        register_result = TpshopApi.register01(self.session, register_data)
        print(register_result.json())
        tpshopcommon.register_assert(register_result, state_code, status, msg)
